package com.propic.www;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Callback;

import java.io.File;

/**
 * Created by geange on 16-5-15.
 */
public class Demo1 extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        TreeItem<File> root = new TreeItem<File>(new File("/home"));
        File roottmp = root.getValue();
        Label rootlabel = new Label();
        Text text = new Text(roottmp.getName());
        rootlabel.setGraphic(text);

        if (roottmp.isDirectory()){
            for (File in : roottmp.listFiles()){
                TreeItem<File> tmp = new TreeItem<>(in);
                root.getChildren().add(tmp);
            }
        }
        System.out.print(root.getValue());
        TreeView<File> rootview = new TreeView<File>(root);
        rootview.setCellFactory(new Callback<TreeView<File>, TreeCell<File>>() {

            @Override
            public TreeCell<File> call(TreeView<File> fileTreeView) {
//                protected void updateItem(File fileTreeView, boolean paramBoolean) {
//                    super.updateItem(fileTreeView, paramBoolean);
//                    if(!isEmpty()) {
//                        Text texttmp = new Text(fileTreeView.getName());
//                        texttmp.setFill(Color.BLUEVIOLET);
//                        setGraphic(texttmp);
//
//                        final TreeCell<File> this$ = this;
//                        this$.applyCss();
//                    }
                return null;
            }
        });
        Scene scene = new Scene(rootview);
        stage.setScene(scene);
        stage.show();
    }

//    public static void addListenForTree()



    public static void main(String[] args){
        launch();
    }
}
